package com.ds.service;

import com.ds.orm.mapper.PermissionDao;
import com.ds.orm.model.Permission;
import com.ds.core.base.BaseService;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Du
 * @since 2017-11-19
 */
@Service
public class PermissionService extends BaseService<Permission> {
	@Autowired
	private PermissionDao permissionDao;

	public Set<Permission> queryPermissionByUserId(long userId) {
		List<Permission> permissions = permissionDao.queryPermissionByUserId(userId);
		if (permissions == null || permissions.size() == 0) {
			return null;
		}
		Set<Permission> result = new HashSet<>();
		for (Permission permission : permissions) {
			result.add(permission);
		}
		return result;
	}

	public Set<Long> queryPermissionIdsByUserId(long userId) {
		Set<Permission> permissions = queryPermissionByUserId(userId);
		Set<Long> result = new HashSet<>();
		for (Permission permission : permissions) {
			result.add(permission.getId());
		}
		return result;
	}
}
